lib: handle sysfs extraction failures by enabling failbit exception#183
lib: handle sysfs extraction failures by enabling failbit exception#183sidtronics wants to merge 1 commit intofenrus75:masterfrom
Conversation
paulmenzel
left a comment
There was a problem hiding this comment.
Awesome, that you came up with a fix. Maybe elaborate in the commit message and give your battery reporting issue as an example? Also give the old and new power usage value?
On some systems, reading a sysfs attribute may fail due to underlying kernel or firmware (BIOS/ACPI) issues. In my case, accessing the "current_now" attribute while on battery power results in: $ cat /sys/class/power_supply/BAT0/current_now cat: /sys/class/power_supply/BAT0/current_now: No such device This commit simplifies the error handling in read_sysfs() function by enabling failbit exception, which also covers the edge case mentioned above. Closes fenrus75#179. Signed-off-by: Siddhesh Dharme <siddheshdharme18@gmail.com>
Thanks! I’ve updated the commit message. Here are before and after screenshots: The discharge rate is now omitted because read_sysfs() fails cleanly and returns 0 when the sysfs read is invalid, instead of parsing garbage values. Since 0 < 0.0001, it's filtered out in the UI: powertop/src/process/do_process.cpp Lines 829 to 836 in 49045c0 I think that's preferable to showing incorrect values. |
[…] Awesome. Thank you for the great commit message, and your thorough answer. Much appreciated! |
dyfrgi
left a comment
There was a problem hiding this comment.
Would it make sense to enable exceptions for the other two failure modes, eof and bad? eof would occur if the file exists but is empty, and bad if there's something like a failure in allocation or other exception caught by the istream operations.
Otherwise, LGTM.


ensure read failure is detected if file is empty or contains invalid data. Closes #179.